package com.one.tank;

import java.awt.*;

//营地
public class Camp {
    //营地状态常量,空闲和运行中
    public final static int CAMP_STATE_FREE = 0;
    public final static int CAMP_STATE_RUNNING = 1;
    //营地左上角X坐标
    private int x;
    //营地左上角Y坐标
    private int y;
    //营地宽度
    private int width = Tank.TANK_WIDTH;
    //营地高度
    private int height = Tank.TANK_HEIGHT;
    //营地状态
    private int state = CAMP_STATE_FREE;
    //元素宽度
    private int elementWidth = 2;
    //元素高度
    private int elementHeight = 2;
    //营地地图 20*20
    private static byte[][] campMap =
            {
                    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                    {0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
                    {1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1},
                    {0, 2, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 2, 0},
                    {1, 1, 2, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 2, 1, 1},
                    {0, 0, 1, 2, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 2, 1, 0, 0},
                    {0, 1, 1, 1, 2, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 2, 1, 1, 1, 0},
                    {0, 0, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0, 0},
                    {0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0, 0, 0},
                    {0, 0, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 0, 0},
                    {0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 0, 0, 0},
                    {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
                    {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
                    {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
                    {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},
                    {0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},
                    {0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0},
                    {0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
                    {0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0},
                    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
            };

    /**
     * 构造函数
     *
     * @param x 营地左上角X坐标
     * @param y 营地左上角Y坐标
     */
    //营地坐标
    public Camp(int x, int y) {
        this.x = x;
        this.y = y;
    }

    //画营地 0-表示空地 1-表示障碍物 2-表示基地
    public void drawCamp(Graphics g) {
        int row = campMap.length;
        int col = campMap[0].length;
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                int mapValue = campMap[i][j];
                if (mapValue == 1) {
                    g.setColor(Color.WHITE);
                    drawElement(g, this.x + j * elementWidth, this.y + i * elementHeight);
                } else if (mapValue == 2) {
                    g.setColor(Color.LIGHT_GRAY);
                    drawElement(g, this.x + j * elementWidth, this.y + i * elementHeight);
                }
            }
        }
    }

    /**
     * 画元素
     *
     * @param x 元素左上角X坐标
     * @param y 元素左上角Y坐标
     */
    public void drawElement(Graphics g, int x, int y) {
        g.fillRect(x, y, elementWidth, elementHeight);
        g.setColor(Color.WHITE);
        g.draw3DRect(x, y, elementWidth, elementHeight, true);
    }
    //setter,getter方法

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }
}
